package com.ruoyi.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.manage.service.IFormSettingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.manage.domain.SurgeryForm;
import com.ruoyi.manage.service.ISurgeryFormService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 手术单关联Controller
 * 
 * @author zww
 * @date 2025-07-14
 */

@RestController
@RequestMapping("/manage/surgeryform")
@Api
public class SurgeryFormController extends BaseController
{
    @Autowired
    private ISurgeryFormService surgeryFormService;
    @Autowired
    private IFormSettingService formSettingService;

    /**
     * 查询手术单关联列表
     */
    @PreAuthorize("@ss.hasPermi('manage:surgeryform:list')")
    @GetMapping("/list")
    public TableDataInfo list(SurgeryForm surgeryForm)
    {
        startPage();
        List<SurgeryForm> list = surgeryFormService.selectSurgeryFormList(surgeryForm);
        return getDataTable(list);
    }
    @ApiOperation("获取带值的表单,带入formSettingId和surgeryFormId")
    @GetMapping("/form")
    public AjaxResult form(SurgeryForm surgeryForm)
    {
        return success(formSettingService.selectForm(surgeryForm));
    }

    /**
     * 导出手术单关联列表
     */
    @PreAuthorize("@ss.hasPermi('manage:surgeryform:export')")
    @Log(title = "手术单关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SurgeryForm surgeryForm)
    {
        List<SurgeryForm> list = surgeryFormService.selectSurgeryFormList(surgeryForm);
        ExcelUtil<SurgeryForm> util = new ExcelUtil<SurgeryForm>(SurgeryForm.class);
        util.exportExcel(response, list, "手术单关联数据");
    }

    /**
     * 获取手术单关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:surgeryform:query')")
    @GetMapping(value = "/{surgeryFormId}")
    public AjaxResult getInfo(@PathVariable("surgeryFormId") Long surgeryFormId)
    {
        return success(surgeryFormService.selectSurgeryFormBySurgeryFormId(surgeryFormId));
    }

    /**
     * 新增手术单关联
     */
    @PreAuthorize("@ss.hasPermi('manage:surgeryform:add')")
    @Log(title = "手术单关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SurgeryForm surgeryForm)
    {
        surgeryForm.setCreateBy(getUsername());
        return toAjax(surgeryFormService.insertSurgeryForm(surgeryForm));
    }

    /**
     * 修改手术单关联
     */
    @PreAuthorize("@ss.hasPermi('manage:surgeryform:edit')")
    @Log(title = "手术单关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SurgeryForm surgeryForm)
    {
        surgeryForm.setUpdateBy(getUsername());
        return toAjax(surgeryFormService.updateSurgeryForm(surgeryForm));
    }

    /**
     * 删除手术单关联
     */
    @PreAuthorize("@ss.hasPermi('manage:surgeryform:remove')")
    @Log(title = "手术单关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{surgeryFormIds}")
    public AjaxResult remove(@PathVariable Long[] surgeryFormIds)
    {
        return toAjax(surgeryFormService.deleteSurgeryFormBySurgeryFormIds(surgeryFormIds));
    }
}
